﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Helena.Areas.Vendedores.Models;

namespace Helena.Controllers
{
    public class HomeController : Controller
    {
        LogicaVendedor db = new LogicaVendedor();

        public ActionResult Index()
        {
            ViewBag.Message = "Login";
            Session["Vendedor"] = new VendedorView();
            db.Salio();
            return View();
        }

        public ActionResult NoSession()
        {
            return View("NoSession");
        }

        public ActionResult Validate(VendedorView vendedor)
        {
            List<VendedorView> vends = db.i_RetornarVendedores();
            foreach (VendedorView vw in vends)
            {
                if ((vw.Usuario == vendedor.Usuario) && (vw.Contrasena == vendedor.Contrasena))
                {
                    db.Entro(vw.ID);
                    Session["Vendedor"] = vw;
                    return RedirectToAction("Index", "Ventas/DetalleVenta");
                }                                       
            }
            return Redirect("../Home/NoSession");         
        }

        public ActionResult Error(string s)
        {
            db.Salio();
            return View("Error");            
        }

        public ActionResult Regresar()
        {
            return RedirectToAction("Index","Home");
        }
    }
}
